package org.groupg.practice.antlr;

public class Interval {
    Double left;        // 左端点值（null表示负无穷）
    BoundType leftType; // 左端点类型
    Double right;       // 右端点值（null表示正无穷）
    BoundType rightType;// 右端点类型
    double resultValue; // 匹配该区间后的结果值

    public boolean contains(double value) {
        // 检查左边界
        boolean leftCheck;
        if (left == null) { // 左端为负无穷
            leftCheck = true;
        } else {
            if (leftType == BoundType.CLOSED) {
                leftCheck = value >= left;
            } else { // OPEN
                leftCheck = value > left;
            }
        }

        // 检查右边界
        boolean rightCheck;
        if (right == null) { // 右端为正无穷
            rightCheck = true;
        } else {
            if (rightType == BoundType.CLOSED) {
                rightCheck = value <= right;
            } else { // OPEN
                rightCheck = value < right;
            }
        }

        return leftCheck && rightCheck;
    }
}